package com.example.cymjoe.huaweishopping.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by cymjoe on 2016/12/5.
 */
public class GDTPAdapter extends PagerAdapter {
private Context context;

private   List<String> imgNormalList;

    public GDTPAdapter(Context context, List<String> imgNormalList) {
        this.context = context;
        this.imgNormalList = imgNormalList;
    }

    @Override
    public int getCount() {
        return imgNormalList!=null?imgNormalList.size():0;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View ret = null;
        ImageView imageView = new ImageView(context);
        imageView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,500));

        //imageView.setScaleType(ImageView.ScaleType.fix);
        String s = imgNormalList.get(position);

        Picasso.with(context).load(s).into(imageView);
        ret=imageView;
        container.addView(ret);
        return ret;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {

        return view==object;
    }
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        if (object instanceof View) {
            View view = (View) object;
            container.removeView(view); //移除
        }
    }
}
